package com.ambulance.project.biz.controller.manager;

import com.ambulance.common.utils.poi.ExcelUtil;
import com.ambulance.framework.aspectj.lang.annotation.Log;
import com.ambulance.framework.aspectj.lang.enums.BusinessType;
import com.ambulance.framework.web.controller.BaseController;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.framework.web.page.TableDataInfo;
import com.ambulance.project.manager.domain.BizCardevice;
import com.ambulance.project.manager.service.IBizCardeviceService;
import com.ambulance.project.manager.utils.MgtCommonUtil;
import com.ambulance.project.manager.utils.MgtUserLoginResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车载设备管理Controller
 *
 * @author zr
 * @date 2020-05-28
 */
@RestController
@RequestMapping("/manager/carDevice")
public class BizCardeviceController extends BaseController {
    @Autowired
    private IBizCardeviceService bizCardeviceService;
    @Autowired
    private MgtCommonUtil mgtCommonUtil;

    /**
     * 查询车载设备管理列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizCardevice bizCardevice) {
        startPage();
        List<BizCardevice> list = bizCardeviceService.selectBizCardeviceList(bizCardevice);
        return getDataTable(list);
    }

    /**
     * 导出车载设备管理列表
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:export')")
    @Log(title = "车载设备管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizCardevice bizCardevice) {
        List<BizCardevice> list = bizCardeviceService.selectBizCardeviceList(bizCardevice);
        ExcelUtil<BizCardevice> util = new ExcelUtil<BizCardevice>(BizCardevice.class);
        return util.exportExcel(list, "carDevice");
    }

    /**
     * 获取车载设备管理详细信息
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:query')")
    @GetMapping(value = "/{deviceID}")
    public AjaxResult getInfo(@PathVariable("deviceID") Long deviceID) {
        return AjaxResult.success(bizCardeviceService.selectBizCardeviceById(deviceID));
    }

    /**
     * 获取车载设备管理详细信息
     */
    @GetMapping(value = "dispatchLog/{deviceID}")
    public AjaxResult getDispatchLog(@PathVariable("deviceID") Long deviceID) {
        return AjaxResult.success(bizCardeviceService.selectBizCardeviceDisaptchLogById(deviceID));
    }

    /**
     * 新增车载设备管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:add')")
    @Log(title = "车载设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizCardevice bizCardevice) {
        final MgtUserLoginResult mgtUserLoginResult = mgtCommonUtil.getMgtUserLoginResult();
        bizCardevice.setUid(new Long(mgtUserLoginResult.getUid()));
        return toAjax(bizCardeviceService.insertBizCardevice(bizCardevice));
    }

    /**
     * 修改车载设备管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:edit')")
    @Log(title = "车载设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizCardevice bizCardevice) {
        return toAjax(bizCardeviceService.updateBizCardevice(bizCardevice));
    }


    /**
     * 解绑车辆
     *
     * @param bizCardevice
     * @return
     */
    @Log(title = "解绑车辆", businessType = BusinessType.UPDATE)
    @PutMapping("/unbundle")
    public AjaxResult unbundle(@RequestBody BizCardevice bizCardevice) {
        bizCardevice.setCarID(null);
        bizCardevice.setCarVin(null);
        return toAjax(bizCardeviceService.updateBizCardevice(bizCardevice));
    }

    /**
     * 删除车载设备管理
     */
    //@PreAuthorize("@ss.hasPermi('manager:carDevice:remove')")
    @Log(title = "车载设备管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deviceIDs}")
    public AjaxResult remove(@PathVariable Long[] deviceIDs) {
        return toAjax(bizCardeviceService.deleteBizCardeviceByIds(deviceIDs));
    }
}
